package com.dcits.electronic_account.controller;

import com.dcits.electronic_account.bean.ResponseJson;
import com.dcits.electronic_account.bean.VirtualAccount;
import com.dcits.electronic_account.constant.Constant;
import com.dcits.electronic_account.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * @Author: CZJ
 * @Date： 2022/6/28
 */

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    /**
     * func 销户
     * @param virtualAccount
     * @return
     */
    @PostMapping("/cancelAccount")
    public ResponseJson cancelAccount(@RequestBody VirtualAccount virtualAccount){
        boolean result = userService.cancelAccount(virtualAccount);
        if (result) return new ResponseJson(Constant.SUCCESS_CODE, "销户成功!");
        return new ResponseJson(Constant.FAIL_CODE, "销户失败!");
    }

    /**
     * func 获取用户信息
     * @param virtualAccount
     * @return
     */
    @PostMapping("getUserInfo")
    public ResponseJson getUserInfo(@RequestBody VirtualAccount virtualAccount){
        VirtualAccount result = userService.getUserInfo(virtualAccount);
        if (result != null) return new ResponseJson(Constant.SUCCESS_CODE, result);
        return new ResponseJson(Constant.FAIL_CODE, result);
    }

    /**
     * func 修改用户信息
     * @param virtualAccount
     * @return
     */
    @PostMapping("/updateUserInfo")
    public ResponseJson updateUserInfo(@RequestBody VirtualAccount virtualAccount){
        HashMap<Boolean, String> result = userService.updateUserInfo(virtualAccount);
        if (result.containsKey(true)) return new ResponseJson(Constant.SUCCESS_CODE, "更新成功!");
        return new ResponseJson(Constant.FAIL_CODE, result.values());
    }
}
